<?php

class ValidateUtil {

    const PHONE_REGEXP = "/^\(?(\+?\d{2}|\d{3})\)?([-. ]?\(?([0-9]+)?\)?)+$/";
    const EMAIL_REGEXP = "/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/";
    const USD_FORMAT = "USD";

    public static function isValidTelephone($number){
        return preg_match(ValidateUtil::PHONE_REGEXP, $number);
    }

    public static function isPrice(&$price,$currency = self::USD_FORMAT){
        if($currency == self::USD_FORMAT){
            if(is_numeric($price)){
                $price = sprintf("%.2f",($price));
                return true;
            }
            return false;
        }
        return false;
    }

    public static function isPercent($price){
        if(ctype_digit($price) && $price > 0 && $price <= 100) {
            return true;
        }
        return false;
    }
    
    public static function isEmail($email){
        return preg_match(ValidateUtil::EMAIL_REGEXP, $email);
    }
}
